<template>
    <div class = "newsmain">
        <p class= "newshead"><i class="el-icon-s-promotion"> 新闻列表</i></p>
        <div class = "newsleft">
            <ul class="newsul">

                <li v-for="news in newsList" :key="news.id" @click="info(news.id)">
                    <p style=" display: inline-block;width:88%"><span class="item-type" :class="{newsStyle:news.type == 1}" v-if='news.type==1'>热点</span>
                    <span class="item-type"  v-else-if='news.type==0'>新闻</span> 
                    <span class="item-type" :class="{newsStyle2:news.type == 2}" v-else-if='news.type==2'>置顶</span> 
                     &nbsp; &nbsp;{{news.title}}</p>
                   
                   <span class="newsdate" >{{dateFor(news.created)}}</span>
                </li>
            </ul>
        
            <el-pagination
             @size-change="sizeChangeHandle"
             @current-change="currentChangeHandle"
             :current-page="pageIndex"
             :page-size="pageSize"
             :total="totalPage"
              background=""
              layout="prev, pager, next"
              style="margin-left:38%"
            >
             </el-pagination>
        </div>

        <div class="newsright">
            <img src="../../assets/ban3.jpg" alt="" style="margin-top:5px">
            <img src="../../assets/ban4.jpg" alt="">
        </div>
           
    </div>
</template>

<script>
import news from '@/api/news'
import moment from 'moment'
export default {
    data() {
      return{
          newsList:[],
          pageIndex: 1,
          pageSize: 8,
          totalPage: 0,
      }
    },
    created(){
         this.getnewslist()
    },
       methods: {
            info(id){
                this.$router.push({ path:'/news/'+id  })
            },
            dateFor(date){
                if(date == undefined){return ''};
                return moment(date).format("YYYY-MM-DD")
            },
            getnewslist(){
                news.getnewslist(this.pageIndex,this.pageSize)
                .then(response =>{
                    this.newsList=response.data.page.list
                    console.log( this.newsList)
                     this.totalPage = response.data.page.totalCount
                })
            },
            sizeChangeHandle (val) {
                this.pageSize = val
                this.pageIndex = 1
                this.getnewslist()
            },
      // 当前页
            currentChangeHandle (val) {
            this.pageIndex = val
            this.getnewslist()
            },
       }
}
</script>

<style scoped>
.newshead{
    font-size:18px;
    margin-left:6%;
}
.el-icon-s-promotion{
    color:rgb(0,98,161)
}
.item-type {
    color: #6388c5;
    border: 1px #6388c5 solid;
    display: inline-block;
    vertical-align: middle;
    width: 36px;
    height: 20px;
    box-sizing: border-box;
    font-size: 12px;
    line-height: 18px;
    text-align: center;
}
.newsStyle{
     color:red;
     border: 1px red solid;
}
.newsStyle2{
     color:#bb9a6c;
     border: 1px #c5ab86 solid;
}
.newsmain{
   width:100%;
   background-color: rgb(238,238,238);
   padding-top:80px;
   display: inline-block;
   overflow: hidden;
   position: relative;
   min-height: 1000px;
 }
 .newsleft{
   width:60%;
   height:800px;
   background-color:white;
   left:6%;
   box-shadow: 0 0 10px #ddd;
   margin-top: 30px;
   display: inline-block;
   position: absolute;
 }
 
 .newsul{
     list-style: none;
     width: 100%;
 }
.newsul li{
     width: 95%;
     height: 90px;
     border-bottom: 1px solid gainsboro;
     line-height: 110px;
     cursor: pointer;
 }
 
.newsdate{
     display: inline-block;
     font-size: 14px;
     color: #9d9d9d;
 }
 .newsright{
     width: 25%;
     height:600px;
     display: inline-block;
     right:6%;
     position: absolute;
     margin-top:30px

 }

 .newsright img{
     width:90%;
     margin-left:5%;
     border-radius: 10px;
     margin-top: 50px;
 }
</style>